using System;
using System.Collections.Generic;
using System.Linq;

namespace DIS_WEB_Client.Repositories
{
	#region using
	using DIS_WEB_Client.Helpers;
    using DIS_Web_Client.DIS_WS_BusinessLayer;
	#endregion
	public class DailyReportRepository
	{
		public DailyReportDTO SelectByID(int id)
		{
			try
			{
                return BusService.Instance.DailyReport_SelectByID(id);
			}
			catch(Exception ex)
			{
				if (ex.InnerException != null)
				{
					GlobalVariables.Logger.Error(ex.InnerException.Message);
				}
				else
				{
					GlobalVariables.Logger.Error(ex.Message);
				}
			}
			return null;
		}

		public bool Insert(DailyReportDTO obj)
		{
			try
			{
                return BusService.Instance.DailyReport_Insert(obj);
			}
			catch(Exception ex)
			{
				if (ex.InnerException != null)
				{
					GlobalVariables.Logger.Error(ex.InnerException.Message);
				}
				else
				{
					GlobalVariables.Logger.Error(ex.Message);
				}
			}
			return false;
		}

		public List<DailyReportDTO> RetrieveByID(int id)
		{
			try
			{
                var item = BusService.Instance.DailyReport_SelectByID(id);
                if (item != null)
                {
                    return new List<DailyReportDTO> { item };
                }
			}
			catch(Exception ex)
			{
				if (ex.InnerException != null)
				{
					GlobalVariables.Logger.Error(ex.InnerException.Message);
				}
				else
				{
					GlobalVariables.Logger.Error(ex.Message);
				}
			}
			return new List<DailyReportDTO>();
		}

		public List<DailyReportDTO> SelectByIDChemistWareHouse(int idChemistWareHouse)
		{
			try
			{
                return BusService.Instance.DailyReport_SelectByIDChemistWareHouse(idChemistWareHouse).OrderByDescending(n => n.ReportDate).ToList();
			}
			catch(Exception ex)
			{
				if (ex.InnerException != null)
				{
					GlobalVariables.Logger.Error(ex.InnerException.Message);
				}
				else
				{
					GlobalVariables.Logger.Error(ex.Message);
				}
			}
			return new List<DailyReportDTO>();
		}

        public DailyReportDTO SelectByIDChemistWareHouseAndReportDate(int idChemistWareHouse, DateTime reportdate)
        {
            try
            {
                return BusService.Instance.DailyReport_SelectByIDChemistWareHouseAndReportDate(idChemistWareHouse, reportdate);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    GlobalVariables.Logger.Error(ex.InnerException.Message);
                }
                else
                {
                    GlobalVariables.Logger.Error(ex.Message);
                }
            }
            return null;
        }
	}
}